<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Limb3 JS Tests</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="../lib/prototype.js" type="text/javascript"></script>
  <script src="../lib/unittest.js" type="text/javascript"></script>

  <script src="../../shared/limb.js" type="text/javascript"></script>
  <script src="../../shared/limb/Browser.js" type="text/javascript"></script>
  <link rel="stylesheet" href="../test.css" type="text/css" />
</head>
<body>
<h1>Limb.Exception test</h1>

<!-- Log output -->
<div id="testlog"> </div>

<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[

new Test.Unit.Runner({
  testThrowException: function()
  {
    try
    {
      throw new Limb.Exception('TestException', 'This is a test message');
    }
    catch(error)
    {
      this.assertEqual('TestException', error.getType(), 'Type is no set');
      this.assertEqual('This is a test message', error.getMessage(), 'Message is no set');
      this.assert(error.getStack(), 'Stack is no set');
      this.assert(error.getLineNumber(), 'LineNumber is no set');
      this.assert(error.getFileName()), 'FileName is no set';
    }
  },

  testWrapNativeException: function()
  {
    try
    {
      Some.object = 5;
    }
    catch(error)
    {
      var ex = new Limb.Exception(error);
      this.assert(ex.getMessage(), 'Message is not set');
      this.assert(ex.getType(), 'Type is not set');
      this.assert(ex.getStack(), 'Stack is not set');
      this.assert(ex.getFileName(), 'FileName is not set');
      this.assert(ex.getLineNumber(), 'LineNumber is not set');

      this.assertEqual(error.message, ex.getMessage(), 'Message not copied from native exception');

      if(Limb.Browser.is_ie)
      {
        this.assertEqual('LimbException', ex.getType(), 'Default Type not assigned');
        this.assertEqual('Stack is not available', ex.getStack(), 'Default Stack not assigned');
        this.assertEqual('File name is not available', ex.getFileName(), 'Default FileName not assigned');
        this.assertEqual('Line number is not available', ex.getLineNumber(), 'Default LineNumber not assigned');
      }
      else
      {
        this.assertEqual(error.stack, ex.getStack(), 'Stack not copied from native exception');
        this.assertEqual(error.fileName, ex.getFileName(), 'FileName not copied from native exception');
        this.assertEqual(error.lineNumber, ex.getLineNumber(), 'LineNumber not copied from native exception');
      }
    }
  },

  testToString: function()
  {
    var ex = new Limb.Exception('TestException');
    this.assertEqual('[ exception TestException ]', ex.toString());
  }
});

// ]]>
</script>
</body>
</html>